package com.niit.project.service.impl;

import com.niit.project.dao.AdminDao;
import com.niit.project.dao.impl.AdminDaoImpl;
import com.niit.project.entity.Admin;
import com.niit.project.service.AdminService;
import com.niit.project.utils.Dbutils;

public class AdminServiceImpl implements AdminService {
    private AdminDao adminDao = new AdminDaoImpl();
    @Override
    public Admin login(String name, String password) {
        Admin admin = null;
        try {
            Dbutils.begin();
            //通过姓名选取管理员信息,将其存储到teno对象中
            Admin temp = adminDao.select(name);
            //如果temp不为空,即存在这样的管理员对象则继续进行密码的判断
            if(temp!=null)
            {
                if(temp.getPassword().equals(password))
                {
                    admin = temp;
                }

            }
            //事务的提交
            Dbutils.commit();
        } catch (Exception e) {
            //如果有异常则回滚
            Dbutils.rollback();
            throw new RuntimeException(e);
        }
        return admin;

    }
}
